<script>
  var countBaPairs = function (nums) {
    let map = new Map();
    let len = nums.length;
    for (let i = 0; i < len; i++) {
      if (map.has(nums[i] - i)) {
        map.set(nums[i] - i, map.get(nums[i] - i) + 1)
      } else {
        map.set(nums[i] - 1, 1)
      }
    }
    let res = 0;
    for (let i of map.values()) {
      res += i * (i - 1) / 2
    }
    return len * (len - 1) / 2 - res
  }
  console.log(countBaPairs(nums = [4, 1, 3, 3]))
</script>